home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-15 | 5.8 KB | 148 lines | [TEXT/ALFA] |
- ####################################################################
- # EvoX - evolution in complex systems
- #
- # FILE: "smarterSource.tcl"
- # created: 4/7/95 {1:44:01 pm}
- # last update: 4/7/95 {1:46:55 pm}
- # Author: Vince Darley
- # E-mail: <mailto:vince@das.harvard.edu>
- # mail: Division of Applied Sciences, Harvard University
- # Oxford Street, Cambridge MA 02138, USA
- # <http://www.das.harvard.edu/users/students/Vincent_Darley/>
- #
- ####################################################################
-
- ##
- # This file is part of the package "Vince's Additions".
- # See its documentation for more details.
- #
- # Bug reports and feature requests - please email me.
- ##
-
- #############################################################################
- # BASED UPON 'smartSource.tcl':
- #
- # Copyright 1994, Robert Browning (osiris@cs.utexas.edu): This code is made
- # freely available to anyone who can find a use for it. Consider it part of my
- # thanks to all those who have contributed to the freeware and shareware base.
- # (Especially Pete Keheler, without which this code would be pretty useless).
- #
- # === Modifications by Vince, May 1995 ===
- #
- #############################################################################
- #
- # This file implements a replacement source command. It is intended to help
- # make the process of augmenting Alpha's code base with your own changes less
- # awkward, especially in the face of program updates. It also makes it so
- # that you no longer have to source files containing procedures that you want
- # to override in your UserStartup file.
- #
- # Basically, you designate a directory (right now it has to be a directory
- # named TclExtensions in the $HOME directory) to contain your files. Then
- # anytime Alpha is instructed to source a file named filename.tcl, it will
- # first look in the directory you have designated, and if there is a file of
- # the identical name there (i.e. filename.extension) it will source that file
- # instead of the original one specified. If there are any files named
- # filename+*.extension it will source those in the order returned by glob after
- # either the original filename.extension or the replacement has been sourced.
- #
- # For example, if your TclExtensions directory contains files named
- # latex+1.tcl and latex+2.tcl, then whenever you try to open a latex file
- # Alpha will first source the standard latex.tcl file, then latex+1.tcl, then
- # latex+2.tcl. If there was also a file named latex.tcl in the TclExtensions
- # directory then that file would be sourced in place of the standard
- # latex.tcl, then latex+1.tcl, then latex+2.tcl.
- #
- # You may just want to use filename+.extension for a single extension file.
- #
- # Note that latex+10.tcl would be sourced _before_ latex+9.tcl, so you
- # may wish to use latex+01.tcl ... latex+99.tcl to make things clearer.
- #
- #############################################################################
- # Fixes:
- #
- # 10/10/94: Fixed it to handle non .tcl file extensions.
- # 01/05/95: Resent to Pete due to earlier transmission error that replaced
- # + characters with * characters.
- #
- #############################################################################
- # To Do:
- #
- # What do you want?
-
- ##
- # VMD May'95: <mailto:vince@das.harvard.edu>
- #
- # Changed default directory to the the alpha preferences directory.
- # Changed extension to '+' rather than 'bullet' (option-8) because
- # of ascii transmission problems - lots of people have a non-working
- # version of this file.
- #
- # Passes through 'tclIndex' and 'prefs.tcl' unchanged.
- #
- # Renamed this file to 'smarterSource.tcl', originally just to differentiate
- # it from the old crippled versions.
- #
- # IMPORTANT: Fixed the script so that it works with path names containing
- # spaces.
- #
- # Now implements part of a new mode-specific preferences mechanism. Every
- # Alpha mode should have a 'dummy${mode}' proc, which is called to ensure
- # a particular mode's tcl files have been sourced. If such a file is
- # sourced, smarterSource will subsequently source a file '${mode}Prefs.tcl'
- # in the preferences directory, if it exists.
- #
- # See "modePrefs.tcl", for the other bits of the implementation.
- ##
-
- set tclExtensionsDir "$PREFS"
-
- if {!$skipPrefs && [file exists "${tclExtensionsDir}"]} {
- if {![string length [info commands oldSource]]} {
- rename source oldSource
- }
- proc source {filename} {
- global tclExtensionsDir modeFiles PREFS
- set justName [file tail "$filename"]
- set overrideFile "${tclExtensionsDir}:${justName}"
-
- # changed '#0' to '1'
- if { $justName == "tclIndex" } { return [uplevel 1 oldSource ¥{$filename¥} ] }
- if { $justName == "prefs.tcl" } { return [uplevel #0 oldSource ¥{$filename¥} ] }
-
- if {[file exists $overrideFile]} {
- set returnVal [uplevel #0 oldSource ¥{$overrideFile¥} ]
- } else {
- set returnVal [uplevel #0 oldSource ¥{$filename¥} ]
- }
-
- set baseName [string range ${justName} 0 ¥
- [expr [string length ${justName}] - ¥
- [string length [file extension ${justName}]] - 1]]
-
- ##
- # Mode specific preferences stuff
- ##
- if [array exists modeFiles] {
- if { [lsearch [array names modeFiles] $justName] != -1 } {
- foreach m $modeFiles($justName) {
- set f "${PREFS}:${m}Prefs.tcl"
- if [file exists "$f" ] {
- set returnVal [uplevel #0 oldSource ¥{$f¥} ]
- }
- }
- }
- }
-
- set extensionFiles ¥
- [glob -nocomplain ¥
- "${tclExtensionsDir}:${baseName}+*[file extension ${justName}]"]
-
- foreach extensionFile $extensionFiles {
- set returnVal [uplevel #0 oldSource ¥{$extensionFile¥} ]
- }
- return "$returnVal"
- }
- }
-
-